﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Data.Common;
using Data.Enum;
using DataAccess.FinancialManage;
using Ninject;
using WinForm.Helper;

namespace WinForm.SystemManage
{
    public partial class AssetConfrim : Form
    {
        private static readonly IKernel Kernel = new StandardKernel(new DbModule());
        private readonly IFinancial _financial = Kernel.Get<Financial>();

        private jsh_property selfPro = null;

        /// <summary>
        /// 是否是退出系统
        /// </summary>
        private bool isExit = false;

        public AssetConfrim()
        {
            InitializeComponent();

            try
            {
                ResultInfo<jsh_property> jshProperty = _financial.GetTopProperty(SystemInfo.OperateAddressId);
                if (jshProperty.ResultNumber == ResultEnum.Success)
                {
                    selfPro = jshProperty.Obj;
                    labelX3.Text =
                        (jshProperty.Obj.Currentmoney + jshProperty.Obj.Currentreceiptmoney + jshProperty.Obj.Fixmoney).
                            ToString();
                    labelX4.Text = (jshProperty.Obj.Currentcardcounts + jshProperty.Obj.Fixcards).ToString();
                }
            }
            catch (Exception)
            {
                MyMessageBox.ShowMessageBoxInfo("获取资产确认信息出现错误，请联系管理员！");
            }
        }

        public AssetConfrim(bool isExit)
        {
            this.isExit = isExit;

            InitializeComponent();

            try
            {
                ResultInfo<jsh_property> jshProperty = _financial.GetTopProperty(SystemInfo.OperateAddressId);
                if (jshProperty.ResultNumber == ResultEnum.Success)
                {
                    selfPro = jshProperty.Obj;
                    labelX3.Text =
                        (jshProperty.Obj.Currentmoney + jshProperty.Obj.Currentreceiptmoney + jshProperty.Obj.Fixmoney).
                            ToString();
                    labelX4.Text = (jshProperty.Obj.Currentcardcounts + jshProperty.Obj.Fixcards).ToString();
                }
            }
            catch (Exception)
            {
                MyMessageBox.ShowMessageBoxInfo("获取资产确认信息出现错误，请联系管理员！");
            }
        }

        private void buttonX1_Click(object sender, EventArgs e)
        {
            if(selfPro==null)
            {
                ResultInfo<jsh_property> jshProperty = _financial.GetTopProperty(SystemInfo.OperateAddressId);
                if (jshProperty.ResultNumber == ResultEnum.Success)
                {
                    selfPro = jshProperty.Obj;
                }
            }
            ResultInfo<int> p = _financial.CreateProperty(0, 0, 0, 0, 0, 0, selfPro==null?0:selfPro.Fixmoney, selfPro==null?0:selfPro.Fixcards, "自动检查资产状况，确认无误！");
            if(p.ResultNumber==ResultEnum.Error)
            {
                MyMessageBox.ShowMessageBoxError("资产确认出现错误，请联系管理员！");
            }else
            {
                if(!this.isExit)
                {
                    Visible = false;
                    //显示主界面
                    var frmNew = new FrmNew { StartPosition = FormStartPosition.CenterScreen };

                    frmNew.ShowDialog();
                }
                Close();
                Dispose();
            }
        }

        private void buttonX2_Click(object sender, EventArgs e)
        {
            Visible = false;
            HandleAssetConfirm handleAssetConfirm=new HandleAssetConfirm(this.isExit);
            handleAssetConfirm.ShowDialog();
            Close();
            Dispose();
        }
    }
}
